package com.hmkj.core.service.order.impl;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.common.baseMapper.GenericPo;
import com.hmkj.common.utils.DateUtils;
import com.hmkj.core.mapper.order.OrderOperationMapper;
import com.hmkj.core.po.order.Order;
import com.hmkj.core.po.order.OrderOperation;
import com.hmkj.core.po.system.Admin;
import com.hmkj.core.service.order.OrderOperationService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 操作日志表业务相关Service接口实现<br>
 *
 * @author eproo
 * @ClassName: OrderOperationServiceImpl
 * @date 2018-07-10 02:16:17
 */
@Service
@Scope("prototype")
@Transactional(rollbackFor = Exception.class)
public class OrderOperationServiceImpl implements OrderOperationService {

    @Resource
    private OrderOperationMapper orderOperationMapper;

    @Override
    public GenericMapper<OrderOperation, Integer> _getMapper() {
        return orderOperationMapper;
    }

    @Override
    public void saveOrderOperation(Order order, String operation) {
        orderOperationMapper.insert(new OrderOperation(t -> {
            t.setOrderId(order.getId());
            t.setOperation(operation);
            t.setOperationTime(DateUtils.getNow());
        }));
    }

    @Override
    public void saveOrderOperationAdmin(Order order, String operation, Admin admin){
        orderOperationMapper.insert(new OrderOperation(a->{
             a.setOrderId(order.getId());
             a.setOperation(operation);
             a.setOperationTime(DateUtils.getNow());
             a.setCreator(admin.getName());
             a.setUpdator(admin.getName());
        }));
    }
}
